/*
 * Copyright (c) [2019] [Peking University]
 * [BDWare-DOIP] is licensed under the Mulan PSL v1.
 * You can use this software according to the terms and conditions of the Mulan PSL v1.
 * You may obtain a copy of Mulan PSL v1 at:
 *
 *   http://license.coscl.org.cn/MulanPSL
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
 * PURPOSE.
 * See the Mulan PSL v1 for more details.
 */
package bdware.netty.codec.doip;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

public class MessageDecoder extends ByteToMessageDecoder {
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
        try {
            DOMessage msg = new DOMessage();
            msg.majorVersion = in.readByte();
            msg.minVersion = in.readByte();
            msg.flag = in.readByte();
            in.readByte(); // ignore flag reserved;
            in.readInt(); // ignore reserved
            msg.requestId = in.readInt();
            msg.sequenceNumber = in.readInt();
            msg.msgLength = in.readInt();
            msg.header = decodeHeader(in);
            msg.body = decodeBody(in);
            msg.credential = decodeCredential(in);
            out.add(msg);
        } catch (Exception e) {
            e.printStackTrace();
        } finally{
        }
        return;
    }
    // TODO
    private DOHeader decodeHeader(ByteBuf in) {
        return null;
    }

    private DOBody decodeBody(ByteBuf in) {
        return null;
    }

    private DOCredential decodeCredential(ByteBuf in) {
        return null;
    }
}
